/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2015-07-29     Arda.Fu      first implementation
 */
#include <stdint.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <main.h>
#include <pin_dev_cfg.h>
#include <comp_misc_lib.h>
#include <n32g45x.h>
// #include "usb_lib.h"
// #include <usb_pwr.h>

#define LOG_TAG "main"
#include "elog.h"

// __IO uint8_t PrevXferComplete = 1;
// __IO uint32_t TimingDelay     = 0;
// u8 key_buffer[8]              = {0};
// u8 *Ep1DataPtr                = 0;
// extern u8 *EpOutDataPtrTmp;
// extern u8 *EpInDataPtrTmp;


#define REFER_VOLTAGE       3300
#define CONVERT_BITS        (1 << 12)

static void log_system_init(void)
{
    elog_init();
    elog_set_text_color_enabled(true);
    /* set EasyLogger log format */
    elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_ALL);
    elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_ALL & ~(ELOG_FMT_P_INFO | ELOG_FMT_T_INFO));
    elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_ALL & ~(ELOG_FMT_P_INFO | ELOG_FMT_T_INFO | ELOG_FMT_DIR));
    elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_ALL & ~(ELOG_FMT_P_INFO | ELOG_FMT_T_INFO | ELOG_FMT_DIR));
    elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_ALL & ~(ELOG_FMT_FUNC | ELOG_FMT_T_INFO | ELOG_FMT_P_INFO));
    elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_ALL & ~(ELOG_FMT_FUNC | ELOG_FMT_T_INFO | ELOG_FMT_P_INFO));
    /* start EasyLogger */
    elog_start();
    // elog_set_filter_lvl(ELOG_LVL_DEBUG);
    elog_set_filter_lvl(ELOG_LVL_VERBOSE);
    //    elog_set_output_enabled(false);
    //    elog_set_filter_lvl(get_log_args()->level);
    //    elog_set_output_enabled(get_log_args()->uart_en);
}


// rt_adc_device_t adc_dev;
int main(void)
{
    log_system_init();

    while (1)
    {
        // if (PrevXferComplete)
        // {
        //     PrevXferComplete = 0;

        //     key_buffer[2] = 0x06; //need update this

        //     Ep1DataPtr = key_buffer;
        //     USB_SilWrite(EP1_IN, Ep1DataPtr, 8);
        //     Ep1DataPtr = EpInDataPtrTmp;
        //     key_buffer[2] = 0;
        // }
        // else
        // {
        //     rt_thread_mdelay(1000);
        // }
                    rt_thread_mdelay(1000);

    }
}

